package cloth.controller;

import java.util.ArrayList;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.multiaction.MultiActionController;

//import cloth.service.MD_recommendaionService;
import cloth.service.NoticeService;

//import cloth.service.ProductService;
//import cloth.service.administer.AdProductService;


import cloth.vo.NoticeVO;
import cloth.vo.ProductVO;
//import cloth.vo.administer.NewProductVO;


public class MainController extends MultiActionController{
	
	private ProductService service;
	
	private NoticeService noticeService;
	private MD_recommendaionService mdService;
	private AdProductService adProductService;
	public MainController(){}
	
	public void setPs(ProductService service) {
		this.service = service;
	}
	
	public void setNs(NoticeService noticeService){
		this.noticeService = noticeService;
	}
	
	public void setMds(MD_recommendaionService mdService){
		this.mdService = mdService;
	}
	public void setAps(AdProductService adProductService){
		this.adProductService = adProductService;
	}
	
	
	public ModelAndView handleMainPage(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		// TODO Auto-generated method stub
		ModelAndView mv = new ModelAndView();
		try{
			ArrayList<ProductVO> bestSellerList = service.getProductsByBestSeller();
			
			ArrayList<NoticeVO> noticeList = noticeService.selectNotice();
			ArrayList<ProductVO> mdList = mdService.selectMD_recomendaion();
			ArrayList<NewProductVO> newProductList = adProductService.selectNewProduct();
			
			mv.addObject("newProductList",newProductList);
			mv.addObject("bestSellerList", bestSellerList);
			mv.addObject("mdList",mdList);
			mv.addObject("noticeList",noticeList);
			
			mv.setViewName("main_page");
			
		}catch(Exception ex){
			mv.setViewName("error");
			mv.addObject("error_message", ex.getMessage());
			ex.printStackTrace();
		}
		return mv;
	}
}
